# Maintainer: Rosen Penev <rosenp@gmail.com>

_realname=libirecovery
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.1.0
pkgrel=1
pkgdesc='The libirecovery library allows communication with iBoot/iBSS of iOS devices via USB (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
url='https://www.libimobiledevice.org/'
license=('spdx:LGPL-2.1-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-libimobiledevice-glue"
         "${MINGW_PACKAGE_PREFIX}-readline")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
source=(https://github.com/libimobiledevice/${_realname}/releases/download/${pkgver}/${_realname}-${pkgver}.tar.bz2
        020-Iphlpapi.patch)
sha256sums=('ee3b1afbc0cab5309492cfcf3e132c6cc002617a57664ee0120ae918318e25f9'
            'c7e2e84a1bcb2248fe9b075e10f73b7b8a8fbda85a8d82617ab2bb4f56b6ad93')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/020-Iphlpapi.patch"

  autoreconf -fi
}

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared

  make
}

check() {
  cd "${srcdir}"/build-${MSYSTEM}
  make check
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}
  make install DESTDIR="${pkgdir}"
}
